package org.jsets.fastboot.security.authz;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsets.fastboot.model.BaseResp;
import org.jsets.fastboot.model.Respond;
import org.jsets.fastboot.util.JsonUtils;
import org.jsets.fastboot.util.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;


public class AuthzExceptionHandlerImpl implements IAuthzExceptionHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
		int httpStatus =  HttpStatus.FORBIDDEN.value();
		BaseResp resp = BaseResp.fail(httpStatus, authException.getMessage());
		WebUtils.writeJsonToResponse(response, httpStatus, JsonUtils.toJson(resp));
	}

}